package com.augurit.wf.common.tag.haspriv;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.ComponentTagSupport;

import com.opensymphony.xwork2.util.ValueStack;

@SuppressWarnings("serial")
public class WfHasPrivTag extends ComponentTagSupport {
	private static final String ACTIVITY_SPEPARTOR = ",";
	
	private String activities;
	
	
	@Override
	public Component getBean(ValueStack stack, HttpServletRequest req,
			HttpServletResponse resp) {
		// TODO Auto-generated method stub
		
		WfHasPriv wfHasPriv = new WfHasPriv(stack);
		wfHasPriv.setHasPiv("false");
		
		String activityName = req.getParameter("activityName");
		
		if(activityName != null && activityName.trim().length() > 0){
			if(activities != null){
				String[] activityArray = activities.split(ACTIVITY_SPEPARTOR);
				for(int i = 0; i < activityArray.length; i++){
					if(activityArray[i].equals(activityName)){
						wfHasPriv.setHasPiv("true");
						break;
					}
				}
			}
		}
		//已办、办结视图
		else{
			wfHasPriv.setHasPiv("true");
		}
		return wfHasPriv;
	}

	public String getActivities() {
		return activities;
	}

	public void setActivities(String activities) {
		this.activities = activities;
	}
}
